package listeners

import (
	"github.com/gin-gonic/gin"
	"github.com/shirou/gopsutil/cpu"
	"github.com/shirou/gopsutil/disk"
	"github.com/shirou/gopsutil/mem"
	"time"
)

func RegisterUsage(router *gin.Engine) {
	router.GET("/usages", func(ctx *gin.Context) {
		v, _ := mem.VirtualMemory()
		percent, _ := cpu.Percent(time.Second, false)
		info2, _ := disk.Usage("/")

		data := make(map[string]any)
		data["cpu"] = percent
		data["disk"] = info2
		data["memory"] = v

		ctx.JSON(200, data)
	})
}
